//
//  ChatTopToolBarView.m
//  Btpin
//
//  Created by Vic on 2019/4/15.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "ChatTopToolBarView.h"
#import "ChatItemButton.h"

#define ChatTopToolBarViewBtnTag (3000)

@implementation ChatTopToolBarView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    self.backgroundColor = COLOR_OF_CLEAR;
    
    if ([UD_GetOForK(isUserRole) isEqualToString:@"1"]) { // 招聘者
        NSArray *arr = @[@[@"chat_jiaohuanmingpian_n", @"交换名片"], @[@"chat_fasongjianli_n", @"申请简历"], @[@"chat_shipinmianshi_n", @"视频面试"], @[@"chat_buganxingqu", @"不感兴趣"]];
        CGFloat btnWidth = (WIDTH-20*Scale)/4;
        for (NSInteger i = 0; i < arr.count; i++) {
            ChatItemButton *btn = [[ChatItemButton alloc] initWithFrame:CGRectMake(10*Scale+btnWidth*i, 0, btnWidth, self.frame.size.height) imageName:arr[i][0] text:arr[i][1]];
            btn.tag = i+ChatTopToolBarViewBtnTag;
            [btn addTarget:self action:@selector(btnTap:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
            if (i == 3) {
                btn.userInteractionEnabled = YES;
            } else {
                btn.userInteractionEnabled = NO;
            }
        }
    } else { // 求职者
        NSArray *arr = @[@[@"chat_jiaohuanmingpian_n", @"交换名片"], @[@"chat_fasongjianli_n", @"发送简历"], @[@"chat_buganxingqu", @"不感兴趣"]];
        CGFloat btnWidth = (WIDTH-20*Scale)/3;
        for (NSInteger i = 0; i < arr.count; i++) {
            ChatItemButton *btn = [[ChatItemButton alloc] initWithFrame:CGRectMake(10*Scale+btnWidth*i, 0, btnWidth, self.frame.size.height) imageName:arr[i][0] text:arr[i][1]];
            if (i == 0) {
                btn.tag = ChatTopToolBarViewBtnTag;
            } else if (i == 1) {
                btn.tag = 4+ChatTopToolBarViewBtnTag;
            } else {
                btn.tag = 3+ChatTopToolBarViewBtnTag;
            }
            [btn addTarget:self action:@selector(btnTap:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:btn];
            if (i == 2) {
                btn.userInteractionEnabled = YES;
            } else {
                btn.userInteractionEnabled = NO;
            }
        }
    }
}
- (void)jiaohuanmingpianCanUse:(BOOL)canUse {
    ChatItemButton *btn = (ChatItemButton *)[self viewWithTag:ChatTopToolBarViewBtnTag];
    btn.userInteractionEnabled = canUse;
    btn.imgView.image = [UIImage imageNamed:canUse?@"chat_jiaohuanmingpian":@"chat_jiaohuanmingpian_n"];
}
- (void)shenqingjianliCanUse:(BOOL)canUse {
    ChatItemButton *btn = (ChatItemButton *)[self viewWithTag:ChatTopToolBarViewBtnTag+1];
    btn.userInteractionEnabled = canUse;
    btn.imgView.image = [UIImage imageNamed:canUse?@"chat_fasongjianli":@"chat_fasongjianli_n"];
}
- (void)shipinmianshiCanUse:(BOOL)canUse {
    ChatItemButton *btn = (ChatItemButton *)[self viewWithTag:ChatTopToolBarViewBtnTag+2];
    btn.userInteractionEnabled = canUse;
    btn.imgView.image = [UIImage imageNamed:canUse?@"chat_shipinmianshi":@"chat_shipinmianshi_n"];
}
- (void)buganxingquCanUse:(BOOL)canUse {
    ChatItemButton *btn = (ChatItemButton *)[self viewWithTag:ChatTopToolBarViewBtnTag+3];
    btn.userInteractionEnabled = canUse;
    btn.imgView.image = [UIImage imageNamed:canUse?@"chat_buganxingqu":@"chat_buganxingqu_n"];
}
- (void)fasongjianliCanUse:(BOOL)canUse {
    ChatItemButton *btn = (ChatItemButton *)[self viewWithTag:ChatTopToolBarViewBtnTag+4];
    btn.userInteractionEnabled = canUse;
    btn.imgView.image = [UIImage imageNamed:canUse?@"chat_fasongjianli":@"chat_fasongjianli_n"];
}
- (void)btnTap:(UIButton *)button {
    if (self.delegate && [self.delegate respondsToSelector:@selector(chatTopToolBarViewTap:)]) {
        ChatTopToolBarViewType chatTopToolBarViewType = ChatTopToolBarViewTypeOfDefault;
        switch (button.tag-ChatTopToolBarViewBtnTag) {
            case 0: {
                chatTopToolBarViewType = ChatTopToolBarViewTypeOfChangeBusinessCard;
            } break;
            case 1: {
                chatTopToolBarViewType = ChatTopToolBarViewTypeOfApplyForResume;
            } break;
            case 2: {
                chatTopToolBarViewType = ChatTopToolBarViewTypeOfVideoInterview;
            } break;
            case 3: {
                chatTopToolBarViewType = ChatTopToolBarViewTypeOfLoseInterestIn;
            } break;
            case 4: {
                chatTopToolBarViewType = ChatTopToolBarViewTypeOfSendResume;
            } break;
            default:
                break;
        }
        [self.delegate chatTopToolBarViewTap:chatTopToolBarViewType];
    }
}

@end
